#include <stdio.h>

/* Constant Declarations */
char Look;// Lookahead Character
const int buf_len = 64;

/* Read New Character From Input Stream */
void GetChar() {
  Look = getchar();
}

/* Report an Error */
void WriteLn(const char* s) {
  if (s) {
	printf(s);
  }

  printf("\n");
}

void Error(char* s) {
  WriteLn(0);

  char buf[buf_len] = {0};
  sprintf(buf, "Error: %s.", s);
  WriteLn(buf);
}

/* Report Error and Halt */
void Abort(const char* s) {
  Error(s);
  exit(0);
}

/* Report What Was Expected */
void Expected(const char* s) {
  char buf[buf_len] = {0};
  sprintf(buf, "%s Expected", s);
  Abort(buf);
}

/* Match a Specific Input Character */
void Match(char x) {
  if (Look == x) {
	GetChar();
  }
  else {
	char buf[buf_len] = {0};
	sprintf(buf, "'''' %c ''''", x);
	Expected(buf);
  }
}

/* Recognize an Alpha Character  */
int IsAlpha(char c) {
  return isalpha(c);
}

/* Recognize a Decimal Digit */
int IsDigit(char c) {
  return isdigit(c);
}

/* Recognize an Addop */
int IsAddop(char c) {
  if ((c == '+') ||
	  (c == '-')) {
	return 1;
  }
  else {
	return 0;
  }
}

/* Get an Identifier */
char GetName() {
  if (!IsAlpha(Look)) {
	Expected("Name");
  }

  char result = Look;
  GetChar();
  return result;
}

/* Get a Number */
char GetNum() {
  if (!IsDigit(Look)) {
	Expected("Integer");
  }

  char result = Look;
  GetChar();
  return result;
}

/* Output a String with Tab */
void EmitLn(const char* s) {
  printf("\t %s\n", s);
}

/* Initialize */
void Init() {
  GetChar();
}

/* Parse and Translate a Math Factor */
void Expression(); // Forward Declarations

void Ident() {
  char name = GetName();
  if (Look == '(') {
	Match('(');
	Match(')');
	char buf[buf_len]={0};
	sprintf(buf, "BSR %c", name);
	EmitLn(buf);
  }
  else {
	char buf[buf_len]={0};
	sprintf(buf, "MOVE %c(PC),D0", name);
	EmitLn(buf);
  }
}

void Factor() {
  if (Look == '(') {
	Match('(');
	Expression();
	Match(')');
  }
  else if (IsAlpha(Look)) {
	Ident();
  }
  else {
	char buf[buf_len]={0};
	sprintf(buf, "MOVE #%c,D0", GetNum());
	EmitLn(buf);
  }
}

/* Recognize and Translate a Multiply */
void Multiply() {
  Match('*');
  Factor();
  EmitLn("MULS (SP)+,D0");
}

/* Recognize and Translate a Divide */
void Divide() {
  Match('/');
  Factor();
  EmitLn("MOVE (SP)+,D1");
  EmitLn("DIVS D1,D0");
}

/* Parse and Translate a Math Term */
void Term() {
  Factor();
  while ((Look == '*') || (Look == '/')) {
	EmitLn("MOVE D0,-(SP)");
	switch (Look) {
	case '*': {
	  Multiply();
	  break;
	}
	case '/': {
	  Divide();
	  break;
	}
	  
	default:
	  Expected("Mulop");
	  break;
	}
  }
}

void Add() {
  Match('+');
  Term();
  EmitLn("ADD (SP)+,D0");
}

void Subtract() {
  Match('-');
  Term();
  EmitLn("SUB (SP)+,D0");
  EmitLn("NEG D0");
}

void Expression() {
  if (IsAddop(Look)) {
	EmitLn("CLR D0");
  }
  else {
	Term();
  }
  
  while (IsAddop(Look)) {
	EmitLn("MOVE D0,-(SP)");
	switch (Look) {
	case '+': {
	  Add();
	  break;
	}
	case '-':{
	  Subtract();
	  break;
	}
	default:
	  Expected("Addop");
	  break;
	}
  }
}

void Assignment() {
  char name = GetName();
  Match('=');
  Expression();
  char buf[buf_len]={0};
  sprintf(buf, "LEA %c(PC),A0", name);
  EmitLn(buf);
  EmitLn("MOVE D0,(A0)");
}
  
int main(int argc, char** argv) {
  Init();
  Assignment();
  /* Expression(); */
  if (Look != '\n') {
	Expected("Newline");
  }
}
